Skip to contentSkip to conversation

Change in openvpn[master]: multi_io_init: simplify

Openvpn-devel In review flichtenheld (Code Review) 2 participants 6 messages Sep 23, 2025 – Sep 24, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1758642994000.I9cb8aa6ef01445cb99758583aba8ae8f9ded0862@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email

to review the following change.

Change subject: multi_io_init: simplify
......................................................................

multi_io_init: simplify

We take two values and try to massage them in various ways. But this function only has one caller and that puts exactly the same value into both of them. So simplify the code.

Change-Id I9cb8aa6ef01445cb99758583aba8ae8f9ded0862

---
M src/openvpn/multi.c
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h

3 files changed, 6 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/09/1209/1

src/openvpn/multi.c +1 -1
index 9256127..1d2ee53 100644
@@ -411,7 +411,7 @@
     /*
      * Initialize multi-socket I/O wait object
      */
-    m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
+    m->multi_io = multi_io_init(m->max_clients);
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
     /*
src/openvpn/multi_io.c +4 -7
index ece789c..0bfbb63 100644
@@ -113,21 +113,18 @@
 }
 
 struct multi_io *
-multi_io_init(int maxevents, int *maxclients)
+multi_io_init(const int maxclients)
 {
     struct multi_io *multi_io;
-    const int extra_events = BASE_N_EVENTS;
 
-    ASSERT(maxevents >= 1);
-    ASSERT(maxclients);
+    ASSERT(maxclients >= 1);
 
     ALLOC_OBJ_CLEAR(multi_io, struct multi_io);
-    multi_io->maxevents = maxevents + extra_events;
+    multi_io->maxevents = maxclients + BASE_N_EVENTS;
     multi_io->es = event_set_init(&multi_io->maxevents, 0);
     wait_signal(multi_io->es, MULTI_IO_SIG);
     ALLOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevents);
-    *maxclients = max_int(min_int(multi_io->maxevents - extra_events, *maxclients), 1);
-    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", *maxclients,
+    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", maxclients,
         multi_io->maxevents);
     return multi_io;
 }
src/openvpn/multi_io.h +1 -1
index 07eb3d4..4a3c60d 100644
@@ -61,7 +61,7 @@
 #endif
 };
 
-struct multi_io *multi_io_init(int maxevents, int *maxclients);
+struct multi_io *multi_io_init(int maxclients);
 
 void multi_io_free(struct multi_io *multi_io);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9cb8aa6ef01445cb99758583aba8ae8f9ded0862
Gerrit-Change-Number: 1209
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email )

Change subject: multi_io_init: simplify
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9cb8aa6ef01445cb99758583aba8ae8f9ded0862
Gerrit-Change-Number: 1209
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 23 Sep 2025 16:04:44 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH 1/1 multi_io_init: simplify

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

We take two values and try to massage them in various ways. But this function only has one caller and that puts exactly the same value into both of them. So simplify the code.

Change-Id I9cb8aa6ef01445cb99758583aba8ae8f9ded0862

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1209
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1209
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/multi.c +1 -1
index 9256127..1d2ee53 100644
@@ -411,7 +411,7 @@
     /*
      * Initialize multi-socket I/O wait object
      */
-    m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
+    m->multi_io = multi_io_init(m->max_clients);
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
     /*
src/openvpn/multi_io.c +4 -7
index ece789c..0bfbb63 100644
@@ -113,21 +113,18 @@
 }
 
 struct multi_io *
-multi_io_init(int maxevents, int *maxclients)
+multi_io_init(const int maxclients)
 {
     struct multi_io *multi_io;
-    const int extra_events = BASE_N_EVENTS;
 
-    ASSERT(maxevents >= 1);
-    ASSERT(maxclients);
+    ASSERT(maxclients >= 1);
 
     ALLOC_OBJ_CLEAR(multi_io, struct multi_io);
-    multi_io->maxevents = maxevents + extra_events;
+    multi_io->maxevents = maxclients + BASE_N_EVENTS;
     multi_io->es = event_set_init(&multi_io->maxevents, 0);
     wait_signal(multi_io->es, MULTI_IO_SIG);
     ALLOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevents);
-    *maxclients = max_int(min_int(multi_io->maxevents - extra_events, *maxclients), 1);
-    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", *maxclients,
+    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", maxclients,
         multi_io->maxevents);
     return multi_io;
 }
src/openvpn/multi_io.h +1 -1
index 07eb3d4..4a3c60d 100644
@@ -61,7 +61,7 @@
 #endif
 };
 
-struct multi_io *multi_io_init(int maxevents, int *maxclients);
+struct multi_io *multi_io_init(int maxclients);
 
 void multi_io_free(struct multi_io *multi_io);
 
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: multi_io_init: simplify

A particular way to do extra-complicated nothing really... I have stared at the code for a bit, the flow of "t->options.max_clients" into "m->max_clients" (assigned exactly once), etc. - and also compared the logging before/after.

old: MULTI IO: MULTI_IO INIT maxclients=1024 maxevents=1029

new: MULTI IO: MULTI_IO INIT maxclients=1024 maxevents=1029

same numbers ;-)

Your patch has been applied to the master branch.

commit 945db23ef49c3e8c36c6bef8857058544caa77f6

Author: Frank Lichtenheld
Date:   Tue Sep 23 18:04:53 2025 +0200
     multi_io_init: simplify

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1209
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg33176.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: multi_io_init: simplify
......................................................................

multi_io_init: simplify

We take two values and try to massage them in various ways. But this function only has one caller and that puts exactly the same value into both of them. So simplify the code.

Change-Id I9cb8aa6ef01445cb99758583aba8ae8f9ded0862

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1209
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33176.html

---
M src/openvpn/multi.c
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h

3 files changed, 6 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/09/1209/2

src/openvpn/multi.c +1 -1
index 9256127..1d2ee53 100644
@@ -411,7 +411,7 @@
     /*
      * Initialize multi-socket I/O wait object
      */
-    m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
+    m->multi_io = multi_io_init(m->max_clients);
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
     /*
src/openvpn/multi_io.c +4 -7
index ece789c..0bfbb63 100644
@@ -113,21 +113,18 @@
 }
 
 struct multi_io *
-multi_io_init(int maxevents, int *maxclients)
+multi_io_init(const int maxclients)
 {
     struct multi_io *multi_io;
-    const int extra_events = BASE_N_EVENTS;
 
-    ASSERT(maxevents >= 1);
-    ASSERT(maxclients);
+    ASSERT(maxclients >= 1);
 
     ALLOC_OBJ_CLEAR(multi_io, struct multi_io);
-    multi_io->maxevents = maxevents + extra_events;
+    multi_io->maxevents = maxclients + BASE_N_EVENTS;
     multi_io->es = event_set_init(&multi_io->maxevents, 0);
     wait_signal(multi_io->es, MULTI_IO_SIG);
     ALLOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevents);
-    *maxclients = max_int(min_int(multi_io->maxevents - extra_events, *maxclients), 1);
-    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", *maxclients,
+    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", maxclients,
         multi_io->maxevents);
     return multi_io;
 }
src/openvpn/multi_io.h +1 -1
index 07eb3d4..4a3c60d 100644
@@ -61,7 +61,7 @@
 #endif
 };
 
-struct multi_io *multi_io_init(int maxevents, int *maxclients);
+struct multi_io *multi_io_init(int maxclients);
 
 void multi_io_free(struct multi_io *multi_io);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9cb8aa6ef01445cb99758583aba8ae8f9ded0862
Gerrit-Change-Number: 1209
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email )

Change subject: multi_io_init: simplify
......................................................................

multi_io_init: simplify

We take two values and try to massage them in various ways. But this function only has one caller and that puts exactly the same value into both of them. So simplify the code.

Change-Id I9cb8aa6ef01445cb99758583aba8ae8f9ded0862

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1209
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg33176.html

---
M src/openvpn/multi.c
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h

3 files changed, 6 insertions(+), 9 deletions(-)
src/openvpn/multi.c +1 -1
index 9256127..1d2ee53 100644
@@ -411,7 +411,7 @@
     /*
      * Initialize multi-socket I/O wait object
      */
-    m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
+    m->multi_io = multi_io_init(m->max_clients);
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
     /*
src/openvpn/multi_io.c +4 -7
index ece789c..0bfbb63 100644
@@ -113,21 +113,18 @@
 }
 
 struct multi_io *
-multi_io_init(int maxevents, int *maxclients)
+multi_io_init(const int maxclients)
 {
     struct multi_io *multi_io;
-    const int extra_events = BASE_N_EVENTS;
 
-    ASSERT(maxevents >= 1);
-    ASSERT(maxclients);
+    ASSERT(maxclients >= 1);
 
     ALLOC_OBJ_CLEAR(multi_io, struct multi_io);
-    multi_io->maxevents = maxevents + extra_events;
+    multi_io->maxevents = maxclients + BASE_N_EVENTS;
     multi_io->es = event_set_init(&multi_io->maxevents, 0);
     wait_signal(multi_io->es, MULTI_IO_SIG);
     ALLOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevents);
-    *maxclients = max_int(min_int(multi_io->maxevents - extra_events, *maxclients), 1);
-    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", *maxclients,
+    msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", maxclients,
         multi_io->maxevents);
     return multi_io;
 }
src/openvpn/multi_io.h +1 -1
index 07eb3d4..4a3c60d 100644
@@ -61,7 +61,7 @@
 #endif
 };
 
-struct multi_io *multi_io_init(int maxevents, int *maxclients);
+struct multi_io *multi_io_init(int maxclients);
 
 void multi_io_free(struct multi_io *multi_io);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1209?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9cb8aa6ef01445cb99758583aba8ae8f9ded0862
Gerrit-Change-Number: 1209
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged